<?php

require_once '/../Modele/TypeRepere.php';
require_once '/../Modele/Repere.php';
require_once '/../Modele/Carte.php';
require_once '/../Modele/Saison.php';
require_once '/../Modele/Episode.php';

/**
 * @access public
 * @author Joana
 * @package Mapping_Dead.Contr�leur
 */
class Carte_controleur {

    /**
     * @AssociationType Mapping Dead.Mod�le.Carte
     * @AssociationMultiplicity 1..*
     */
    public $model;

    public function __construct() {
        
    }

    /**
     * @access public
     * @return String
     * @ReturnType String
     */
    public function getCarte() {
        return $this->cheminCarte;
    }

    public function getListeRepere($idPersonnage) {
        $res = array();
        $listeTypeRepere = array();
        $listeRepere = Repere::getElement(array('idPersonnage' => $idPersonnage));
        if (!$listeRepere) {
            return $res;
        }
        foreach ($listeRepere as $repere) {
            if (!isset($listeTypeRepere[$repere->idInfoType])) {
                $listeTypeRepere[$repere->idInfoType] = TypeRepere::getById($repere->idInfoType);
            }
            $res[] = array(
                'lat' => $repere->coordX,
                'long' => $repere->coordY,
                'idType' => $repere->idInfoType,
                'type' => $listeTypeRepere[$repere->idInfoType]->typeRepere,
                'id' => $repere->idRepere,
                'episode' => $repere->idEpisode,
                'info' => $repere->infoResume,
                'idPerso' => $idPersonnage
            );
        }
        return $res;
    }

    /**
     * @access public
     * @return Mapping_Dead.Mod�le.Repere[]
     * @ReturnType Mapping Dead.Mod�le.Repere[]
     */
    public function getAllRepere() {
        return Repere::findall();
    }

    public function getNbSaison() {
        return Saison::getNbElement();
    }

    public function getNbEpisodeBySaison($idSaison) {
        return Episode::getNbElement(array("idSaison" => $idSaison));
    }

    public function getIdEpisode($saison, $numEpisode) {
        return Episode::getElement(array("idSaison" => $saison, "numeroEpisode" => $numEpisode))[0]->idEpisode;
    }

    /**
     * @access public
     * @param float coordX
     * @param float coordY
     * @param String type
     * @param int numEpisode
     * @param int idPersonnage
     * @ParamType coordX float
     * @ParamType coordY float
     * @ParamType type String
     * @ParamType numEpisode int
     * @ParamType idPersonnage int
     */
    public function soumettreRepere($coordX, $coordY, $type, $idPersonnage, $idUser, $idEpisode, $info) {
        $repere = new Repere();
        $repere->coordX = $coordX;
        $repere->coordY = $coordY;
        $repere->idInfoType = $type;
        $repere->idUser = $idUser;
        $repere->statutVote = 1;
        $repere->idCarte = 1;
        $repere->idPersonnage = $idPersonnage;
        $repere->idEpisode = $idEpisode;
        $repere->infoResume = $info;
        return $repere->addElement();
    }

    public function getTypeRepere() {
        $listTypeRepere = TypeRepere::findall();
        $res = array();
        foreach ($listTypeRepere as $typeRepere) {
            $res[] = array('idTypeRepere' => $typeRepere->idTypeRepere,
                'imageRepere' => $typeRepere->imageRepere,
                'typeRepere' => $typeRepere->typeRepere
            );
        }
        return $res;
    }

}
